package com.wj.facedetect.widget;


import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wj.facedetect.R;


public class LoadingDialog extends Dialog {

    private TextView tv;
    private ImageView iv;
    private AnimationDrawable animationDrawable;
    private boolean cancelable = false;

    private boolean fullscreen = false;

    public LoadingDialog(Context context) {
        super(context, R.style.AlertDialogStyle);
        init();
    }

    public LoadingDialog(Context context, boolean fullscreen) {
        super(context, R.style.AlertDialogStyle);
        init();
    }

    @SuppressWarnings("ResourceType")
    private void init() {
        View contentView = View.inflate(getContext(), R.layout.activity_custom_loding_dialog_layout, null);
        if (fullscreen) {
            contentView.setBackground(new ColorDrawable(android.R.color.transparent));
        }
        setContentView(contentView);
        tv = (TextView) findViewById(R.id.tv);
        iv = findViewById(R.id.iv_loading);
        setCancelable(true);
        //animationDrawable = (AnimationDrawable) iv.getDrawable();

    }

    @Override
    public void show() {
        super.show();
//        if (!animationDrawable.isRunning()) {
//            animationDrawable.start();
//        }
    }

    @SuppressLint("NewApi")
    @Override
    public void dismiss() {
        super.dismiss();
//        if (animationDrawable.isRunning()) {
//            animationDrawable.stop();
//        }
    }


    @Override
    public void setCancelable(boolean flag) {
        cancelable = flag;
        super.setCancelable(cancelable);
    }

    @Override
    public void setTitle(CharSequence title) {
        tv.setText(title);
    }

    @Override
    public void setTitle(int titleId) {
        setTitle(getContext().getString(titleId));
    }

}
